//
//  MCWithdrawListView.m
//  ZXZX
//
//  Created by MC on 2018/9/17.
//  Copyright © 2018年 TLYL01. All rights reserved.
//

#import "MCWithdrawListView.h"
#import "MCGetUserGroupDrawConfigModel.h"
#define HEIGHT_ITEM 40
@interface MCWithdrawListView ()

@property (strong,nonatomic) UIView * bgView;

@end

@implementation MCWithdrawListView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}

-(void)createUI{
    self.backgroundColor = [UIColor clearColor];
}

-(void)createBgView{
    
    [self.bgView removeFromSuperview];
    self.bgView = [[UIView alloc]init];
    self.bgView.layer.borderWidth = 0.8;
    self.bgView.layer.borderColor = RGB(136, 136, 136).CGColor;
    self.bgView.backgroundColor = [UIColor clearColor];
    [self addSubview:self.bgView];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.equalTo(self);
    }];
    
}

-(void)setDataSouce:(NSArray *)dataSouce{
    
    _dataSouce = dataSouce;
    
    if (dataSouce.count>0) {
        [self createBgView];
        [self createLabWithTitle:@"提款次数" andTag:0 andIsLeft:YES];
        [self createLabWithTitle:@"手续费标准" andTag:0 andIsLeft:NO];
        for ( int i = 1; i < (dataSouce.count+1) ; i++ ) {
            
            MCCollectMoneyListModel * model = dataSouce[i-1];
            
            NSString * DrawCount=@"";
            NSString * CollectMoney =@"";
            
            NSString * num = [MCMathUnits stringWithDecimalNumber:[model.CollectMoney doubleValue]];
             DrawCount= [NSString stringWithFormat:@"第%@次",model.DrawCount];
            //提款手续费类型（0：无手续费，1：比例，2：固定金额)
            if ([self.FeeMoenyType containsString:@"1"]) {
              
               CollectMoney = [NSString stringWithFormat:@"%@%%",num];
            }else if ([self.FeeMoenyType containsString:@"2"]){

                CollectMoney = [NSString stringWithFormat:@"%@元",num];
            }
            if (i == dataSouce.count) {
                DrawCount = [NSString stringWithFormat:@"第>=%@次",model.DrawCount];
                if ([self.FeeMoenyType containsString:@"1"]) {
                    CollectMoney = [NSString stringWithFormat:@"每笔%@%%",num];
                }else if ([self.FeeMoenyType containsString:@"2"]){
                    CollectMoney = [NSString stringWithFormat:@"每笔%@元",num];
                }
            }
            
            [self createLabWithTitle:DrawCount andTag:i andIsLeft:YES];
            [self createLabWithTitle:CollectMoney andTag:i andIsLeft:NO];
        }
    }
}

-(void)createLabWithTitle:(NSString *)title andTag:(NSInteger)tag andIsLeft:(BOOL)isLeft{
    
    UILabel * lab = [[UILabel alloc]init];
    lab.text=title;
    lab.textColor=RGB(102, 102, 102);
    lab.font = [UIFont systemFontOfSize:14];
    lab.textAlignment=NSTextAlignmentCenter;
    lab.layer.borderWidth = 0.5;
    lab.layer.borderColor = RGB(136, 136, 136).CGColor;
    [self.bgView addSubview:lab];
    if (isLeft) {
        [lab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bgView.mas_top).offset(tag*HEIGHT_ITEM);
            make.left.equalTo(self.bgView);
            make.width.mas_equalTo(G_SCREENWIDTH/2.0-10);
            make.height.mas_equalTo(HEIGHT_ITEM);
        }];
    }else{
        [lab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bgView.mas_top).offset(tag*HEIGHT_ITEM);
            make.right.equalTo(self.bgView);
            make.width.mas_equalTo(G_SCREENWIDTH/2.0-10);
            make.height.mas_equalTo(HEIGHT_ITEM);
        }];
    }

}


+(CGFloat)computeHeight:(NSArray *)info{
    if (info.count<1) {
        return 0;
    }
    return HEIGHT_ITEM*(info.count + 1);
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
